MINIMIZE_FRAC:

	PUSH(FP);
	MOV(FP,SP);
	CMP(IND(FPARG(0)),T_FRACTION);

	JUMP_NE(TYPE_ERROR);
	CMP(INDD(FPARG(0),1),0);
	JUMP_NE(MIN_NOT_Z);
	PUSH(0);
	CALL(MAKE_SOB_INTEGER);
	DROP(1);
	POP(FP);
	RETURN;
MIN_NOT_Z:
	JUMP_LT(MIN_NEG);
	PUSH(R1);
	MOV(R0,INDD(FPARG(0),1));
	MOV(R1,INDD(FPARG(0),2));
GCD_LOOP:
	CMP(R0,R1);
	JUMP_EQ(GCD_OUT);
	JUMP_GT(GCD_A);
	SUB(R1,R0);
	JUMP(GCD_LOOP);
GCD_A:
	SUB(R0,R1);
	JUMP(GCD_LOOP);

GCD_OUT:
	DIV(INDD(FPARG(0),1),R0);
	DIV(INDD(FPARG(0),2),R0);
	CMP(INDD(FPARG(0),2),1);
	JUMP_EQ(SHALEM);
	MOV(R0,FPARG(0));
	POP(R1);
	POP(FP);
	RETURN;
SHALEM:
	PUSH(INDD(FPARG(0),1));
	CALL(MAKE_SOB_INTEGER);
	DROP(1);
	POP(R1);
	POP(FP);

	RETURN;
	

MIN_NEG:
	MOV(R0,FPARG(0)); //NEED TO SEE HOW TO DEAL WITH NEGETIVE FRAC
	POP(FP);
	RETURN;
